$(function() {
	$('#vue_vm_list').hide();
});

var staffInfo = {
	staffId: '',
	name: '',
	cardId: '',
	phoneNumber: '',
	email: '',
	birthday: '',
	jobTitle: '',
	departmentId: '',
	subjectRoomId: getLoginedUser().subjectRoomId,
	dutyId: '',
	managerOfSubjectRoom: '',
	typeOfDuty: '',
	firstEduSchool: '',
	firstEduGraduateTime: '',
	firstEduMajors: '',
	firstEduBack: '',
	maximaEduSchool: '',
	maximaEduGraduateTime: '',
	maximaEduMajors: '',
	maximaEduBack: '',
	entryTime: '',
	contractTime: '',
	status: '',
	photoUrl: '',
	remark: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	accountStatus: '',
	departmentName: '',
	subjectRoomName: getLoginedUser().subjectRoomName,
	dutyName: '',
	personType: '',
	personTypeNaem: '',
};

var view = {
	data: staffInfo
};

if($('#vue_vm').length > 0) {
	var vue_vm = new Vue({
		el: '#vue_vm',
		data: view,
		methods: {
			getImageFullPath: function(iconUrl) {
				return imagePath + '/' + iconUrl;
			}
		}
	});
}

function save() {
	view.data.birthday = $('#birthYear').val() + '-' + $('#birthMonth').val() + '-' + $('#birthDay').val();
	view.data.firstEduGraduateTime = $('#firstEduGraduateYear').val() + '-' + $('#firstEduGraduateMonth').val() + '-' + $('#firstEduGraduateDay').val();
	view.data.maximaEduGraduateTime = $('#maximaEduGraduateYear').val() + '-' + $('#maximaEduGraduateMonth').val() + '-' + $('#maximaEduGraduateDay').val();
	view.data.entryTime = $('#entryYear').val() + '-' + $('#entryMonth').val() + '-' + $('#entryDay').val();
	view.data.contractTime = $('#contractYear').val() + '-' + $('#contractMonth').val() + '-' + $('#contractDay').val();
	
	view.data.managerOfSubjectRoom = (view.data.managerOfSubjectRoom==''? 0: parseInt(view.data.managerOfSubjectRoom));
	view.data.typeOfDuty = (view.data.typeOfDuty==''? 0: parseInt(view.data.typeOfDuty));
	view.data.status = (view.data.status==''? 0: parseInt(view.data.status));
	view.data.accountStatus = (view.data.accountStatus==''? 0: parseInt(view.data.accountStatus));
	view.data.personType = (view.data.personType==''? 0: parseInt(view.data.personType));

	save_basic(path+'/staffInfo/save', {staffInfo:view.data}, function() {
		alert('保存成功');
	});
}

function staffInfo_find() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	
	var searchVal = $.url().param('cardId');
	if(!searchVal) {
		searchVal = $('#searchVal').val();
	}
	
	openWaiting('正在查找');
	
	find_basic(path+'/staffInfo/find', searchVal, function(response) {
		closeWaiting();
		
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				editStaff:function(todo) {
					window.open('1-5-5jggl-2.html?pageParam='+encodeURIComponent(JSON.stringify(todo)));
				},
				deleteStaff:function(staffId) {
					if(confirm('确定要删除此职工的资料吗？')) {
						deleteOne_basic(path+'/staffInfo/deleteOne', staffId);
						$('#vue_vm_list').hide();
					}
				},
				getImageFullPath: function(iconUrl) {
					return imagePath + '/' + iconUrl;
				}
			}
		});
		
		$('#vue_vm_list').show();
	});
}

function staffInfo_findByDepartment() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	
	var departmentId = $('#department_cond_select').val();
	
	openWaiting('正在查找');
	
	find_basic_by_json(path+'/staffInfo/findByDepartment', {departmentId: departmentId}, function(response) {
		closeWaiting();
		
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				editStaff:function(todo) {
					window.open('1-5-5jggl-2.html?pageParam='+encodeURIComponent(JSON.stringify(todo)));
				},
				deleteStaff:function(staffId) {
					if(confirm('确定要删除此职工的资料吗？')) {
						deleteOne_basic(path+'/staffInfo/deleteOne', staffId);
						$('#vue_vm_list').hide();
					}
				},
				getImageFullPath: function(iconUrl) {
					return imagePath + '/' + iconUrl;
				},
				getModelNamesText: function(accountModelConfigForms) {
					var modelNamesText = '';
					
					if(accountModelConfigForms) {
						for(var i=0; i<accountModelConfigForms.length; i++) {
							modelNamesText += (i==0?'':'; ') + accountModelConfigForms[i].sysModelForm.modelName;
						}
					}
					
					return modelNamesText;
				}
			}
		});
		
		$('#vue_vm_list').show();
	});
}